package com.accloud.cloudservice;

import com.accloud.common.ACConfiguration;
import com.accloud.service.ACMsg;
import com.accloud.service.ACProduct;
import com.accloud.service.ACProductMgr;
import com.google.gson.Gson;
import java.util.Arrays;
import java.util.List;

public class ACProductManager extends ACBaseManager implements ACProductMgr {
    public static final String TAG = "ACProductManager";

    ACProductManager() {
        super(ACConfiguration.PRODUCT_SERVICE_NAME, 1, false);
    }

    @Override // com.accloud.service.ACProductMgr
    public void fetchAllProducts(final PayloadCallback<List<ACProduct>> callback) {
        ACMsg req = new ACMsg();
        req.setName("getDomainProduct");
        req.setContext("");
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACProductManager.AnonymousClass1 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(Arrays.asList(((AllProductResponse) new Gson().fromJson(new String(resp.getPayload()),  AllProductResponse.class)).products));
            }
        });
    }

    @Override // com.accloud.service.ACProductMgr
    public void fetchProduct(String subDomain, final PayloadCallback<ACProduct> callback) {
        ACMsg req = new ACMsg();
        req.setName("getProduct");
        req.setContext(subDomain);
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACProductManager.AnonymousClass2 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(((ProductResponse) new Gson().fromJson(new String(resp.getPayload()),  ProductResponse.class)).product);
            }
        });
    }

    private class AllProductResponse {
        private ACProduct[] products;

        private AllProductResponse() {
        }
    }

    private class ProductResponse {
        private ACProduct product;

        private ProductResponse() {
        }
    }
}
